package com.poker.pokerprototype;

import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;

public class PokerPrototype extends Activity {
	/** Called when the activity is first created. */
	AnimationDrawable frameAnimation;
	ImageView poker_prlogo;
	boolean isPlaing = false;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.main);
		ImageView img = (ImageView) findViewById(R.id.scrns);
		img.setBackgroundResource(R.drawable.poker_scr_anim);
		poker_prlogo = (ImageView) findViewById(R.id.poker_prlogo);
		frameAnimation = (AnimationDrawable) img.getBackground();
	}

	public boolean onTouchEvent(MotionEvent event) {
		if (event.getAction() == MotionEvent.ACTION_DOWN && !isPlaing) {
			frameAnimation.start();
			frameAnimation.setVisible(true, true);
			poker_prlogo.setVisibility(View.INVISIBLE);
			MediaPlayer mp = MediaPlayer.create(getBaseContext(), R.raw.cards);
			mp.start();
			mp.setOnCompletionListener(new OnCompletionListener() {

				@Override
				public void onCompletion(MediaPlayer mp) {
					mp.release();
				}
			});
			Log.v("*******", "start Event Touch");
			isPlaing = true;
			tosleep(4000);
			return true;
		}
		return super.onTouchEvent(event);
	}

	private void tosleep(int i) {
		Handler handler = new Handler();
		handler.postDelayed(new Runnable() {
			public void run() {
				isPlaing = false;
				Log.v(">>>>>>>", "isPlaing = false");
			}
		}, i);
	}
}